﻿using System;
using Amazon.SQS;

namespace ShuttleBus.Transports.AmazonSqs
{
    internal class SqsEndpoint : Endpoint, ISqsEndpoint
    {
        private readonly int _secondsToProcessMessage;
        private static Func<AmazonSQS> _sqsClientFactory;
        private IQueue _sqs;

        public SqsEndpoint(Uri uri, Func<AmazonSQS> sqsClientFactoryFactory, int secondsToProcessMessage)
            : base(uri)
        {
            _secondsToProcessMessage = secondsToProcessMessage;
            _sqsClientFactory = sqsClientFactoryFactory;
        }

        public override string Path
        {
            get { return Uri.Host; }
        }

        public override IQueue Initialize(QueueMode mode)
        {
            return _sqs ?? (_sqs = new Sqs(_sqsClientFactory(), this, _secondsToProcessMessage));
        }
    }
}